package com.example.sharedpreferences;

import java.util.Map;

import com.example.service.PreferenceService;

import android.os.Bundle;
import android.preference.Preference;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	private EditText nameText,ageText;
	PreferenceService service;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        nameText=(EditText)this.findViewById(R.id.name);
        ageText=(EditText)this.findViewById(R.id.age);
        service=new PreferenceService(getApplicationContext());
        Map<String, String> params=service.getPreferences();
        nameText.setText(params.get("name"));
        ageText.setText(params.get("age"));
    }

    public void save(View v)
    {
    	String name=nameText.getText().toString();
    	String age=ageText.getText().toString();
    	service.save(name,Integer.valueOf(age));
    	Toast.makeText(getApplicationContext(), R.string.save_success, 1).show();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    
}
